<template>
	<view>
		<!-- 搜索区域 -->
		<view class="top-search">
			<my-search @click="goSearch"></my-search>

		</view>


		<!-- 轮播图区域 -->
		<swiper :indicator-active-color="white" :indicator-dots="true" :autoplay="true" :interval="3000"
			:duration="1000" :circular="true">
			<swiper-item v-for="(item,index) in swiperList" :key="index">
				<navigator class="container" :url="'/subpackage/goods_detail/goods_detail?goods_id='+item.goods_id">
					<image :src="item.image_src" mode="widthFix"></image>
				</navigator>
			</swiper-item>
		</swiper>
		<!-- 导航栏区域 -->
		<view class="nav-list">
			<view class="nav-item" v-for="(item,index) in navList" :key="index" @click="navClickHanlder(item)">
				<image :src="item.image_src" mode="" class="nav-img"></image>
			</view>
		</view>
		<!-- 楼层区域 -->
		<view class="floor-list">
			<!-- 楼层标题 -->
			<view class="floor-item" v-for="(item,index) in floorList" :key="index">
				<image :src="item.floor_title.image_src" mode="" class="floor-img"></image>
				<!-- 楼层图片 -->
				<view class="floor-img-box">
					<!-- 左侧单独一个区域 -->
					<navigator class="left-image-box" :url="item.product_list[0].url">
						<image :src="item.product_list[0].image_src"
							:style="{width:item.product_list[0].image_width+'rpx'}" mode="widthFix"></image>
					</navigator>
					<!-- 右侧小区域 -->
					<view class="right-box">
						<navigator class="right-image-box" v-for="(item1,index1) in item.product_list" :key="index1"
							:url="item1.url" v-show="index1!==0">
							<image :src="item1.image_src" :style="{width:item1.image_width+'rpx'}" mode="widthFix">
							</image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	export default {
		mixins: [badgeMix],
		data() {
			return {
				swiperList: [],
				navList: [],
				floorList: []

			};
		},
		onLoad() {
			this.getSwiperList()
			this.getnavList()
			this.getfloorList()
		},
		methods: {
			async getnavList() {
				const res = await uni.$http.get('/api/public/v1/home/catitems')
				if (res.data.meta.status !== 200) {
					uni.$showMsg("数据获取失败")
				}
				this.navList = res.data.message

			},
			async getSwiperList() {
				const res = await uni.$http.get('/api/public/v1/home/swiperdata')

				if (res.data.meta.status !== 200) {
					return uni.$showMsg("数据请求失败")
				}
				this.swiperList = res.data.message



			},
			navClickHanlder(item) {
				if (item.name == '分类') {
					uni.switchTab({
						url: "/pages/cate/cate"
					})
				}
			},
			async getfloorList() {
				const res = await uni.$http.get('/api/public/v1/home/floordata')
				if (res.data.meta.status !== 200) {
					return uni.$showMsg("数据请求失败")
				}
				res.data.message.forEach(floor => {
					floor.product_list.forEach(prod => {
						prod.url = "/subpackage/goods_list/goods_list?" + prod.navigator_url.split(
							'?')[1]
					})
				})
				this.floorList = res.data.message

			},
			goSearch() {
				uni.navigateTo({
					url: '/subpackage/search/search'
				})
			}
		}

	}
</script>


<style lang="scss">
	.container {
		height: 300px;
	}

	image {
		width: 100%;
		height: 100%;
	}

	.nav-list {
		display: flex;
		justify-content: space-around;
		margin-top: 20px;

	}

	.nav-img {
		width: 128rpx;
		height: 140rpx;
	}

	.floor-img {
		display: flex;
		height: 60rpx;
		width: 100%;
	}

	.right-box {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
	}

	.floor-img-box {
		display: flex;
		padding: 10px;

	}

	.top-search {
		position: sticky;
		top: 0;
		z-index: 10;
	}
</style>